<?php
namespace Home\Controller;
use Think\Controller;

//http://localhost/tp_test/index.php/home/Form/add
//http://localhost/tp_test/index.php/home/Form/read/id/1
//http://localhost/tp_test/index.php/home/Form/edit/id/1
//http://localhost/tp_test/?m=home&c=form&a=edit&id=1
//http://localhost/tp_test/?c=form&a=edit&id=1
namespace Home\Controller;
use Think\Controller;
class FormController extends Controller{

	public function insert(){
  	$Form   =   D('Form');
    if($Form->create()) {
    	$result =   $Form->add();
      if($result) {
				$this->success('数据添加成功！');
      }else{
      	$this->error('数据添加错误！');
      }
    }else{
      $this->error($Form->getError());
    }
/*      
		$Form   =   D('Form');
		$data['title']  =   'ren test';
		$data['content']    =   '表单内容';
		$Form->add($data); 

		$Form   =   D('Form');
		$Form->title  =   'ThinkPHP';
		$Form->content    =   '表单内容';
		$Form->add();		
*/		
  }
  
	public function read($id=0){
   	$Form2 = M("Form"); 
 		// 获取标题 
		$title = $Form2->where('id=2')->getField('title');	
		 $this->assign('title',$title);// 模板变量赋值  
  
    $Form   =   M('Form');
    // 读取数据
    $data =   $Form->find($id);
    if($data) {
        $this->assign('data',$data);// 模板变量赋值
    }else{
        $this->error('数据错误');
		}
    	$this->display();
 		}

	public function edit($id=0){
    $Form   =   M('Form');
    $this->assign('vo',$Form->find($id));
    $this->display();
	}
	
	public function update(){
		$Form2 = M("Form"); 
 		// 要修改的数据对象属性赋值
		$data['id'] = 3;
		$data['title'] = 'ThinkPHP';
		$data['content'] = 'ThinkPHP3.2.3版本发布';
		$Form2->save($data); // 根据条件保存修改的数据 
/*
		$Form3 = M("Form"); 
		// 要修改的数据对象属性赋值
		$data['title'] = 'ThinkPHP';
		$data['content'] = 'ThinkPHP3.2.3版本发布';
		$Form3->where('id=5')->save($data); // 根据条件保存修改的数据
		
		$Form4 = M("Form"); 
 		// 要修改的数据对象属性赋值
		$Form4->title = 'ThinkPHP';
		$Form4->content = 'ThinkPHP3.2.3版本发布';
		$Form4->where('id=5')->save(); // 根据条件保存修改的数据		
*/    
		$Form5 = M("Form"); 
 		// 更改title值
		$Form5->where('id=2')->setField('title','ThinkPHP ren');
		exit;
    $Form   =   D('Form');
    if($Form->create()) {
        $result =   $Form->save();
        if($result) {
            $this->success('操作成功！');
        }else{
            $this->error('写入错误！');
        }
    }else{
        $this->error($Form->getError());
    }
 	} 		
        	
}